/**
 * Copyright &copy; 2020 <a href="https://github.com/somowhere/exam-system">exam-system</a> All rights reserved.
 */
package com.shanhesoft.java.modules.exam.web;


import com.shanhesoft.java.common.core.constant.CommonConstants;
import com.shanhesoft.java.common.core.vo.PageModel;
import com.shanhesoft.java.common.data.util.QueryWrapperUtil;
import com.shanhesoft.java.common.log.annotation.LogOperate;
import com.shanhesoft.java.common.log.enums.BusinessType;
import com.shanhesoft.java.common.web.resource.BaseResource;
import com.shanhesoft.java.common.core.util.Result;
import lombok.extern.slf4j.Slf4j;
import io.swagger.annotations.ApiOperation;
import com.shanhesoft.java.modules.exam.domain.dto.TVTrainCommentsDto;
import com.shanhesoft.java.modules.exam.domain.dto.TVTrainCommentsQueryCriteria;
import com.shanhesoft.java.modules.exam.service.TVTrainCommentsService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import lombok.AllArgsConstructor;

import javax.validation.Valid;
import java.util.Set;

/**
 * 实验评论Controller 实验评论
 * @author superadmin
 * @version 2021-01-26 15:25:22
 */
@RestController
@RequestMapping(value = "${application.admin-path}/exam/trainComments")
@Slf4j
@AllArgsConstructor
public class TVTrainCommentsResource extends BaseResource {

	private final TVTrainCommentsService service;

	/**
	 * @param id
	 * @return
	 */
	@GetMapping(CommonConstants.URL_ID_REGEX)
	@PreAuthorize("@pms.hasPermission('exam_tVTrainComments_view')")
	public Result get(@PathVariable String id) {
		log.debug("REST request to get Entity : {}", id);
		return  Result.buildOkData(service.getOneDto(id));
	}
	/**
	 * GET / : get all tVTrainComments.
	 *
	 * @param pm the pagination information
	 * @return the Result with status 200 (OK) and with body all tVTrainComments
	 */

	@PreAuthorize("@pms.hasPermission('exam_tVTrainComments_view')")
	@GetMapping
	@ApiOperation(value = "实验评论查看")
	public Result getPage(PageModel pm, TVTrainCommentsQueryCriteria tVTrainCommentsQueryCriteria) {
		QueryWrapper wrapper = QueryWrapperUtil.getWrapper(pm, tVTrainCommentsQueryCriteria);
		return Result.buildOkData(service.page(pm, wrapper));
	}

	@GetMapping("/treePage")
	@ApiOperation(value = "实验评论查看-前台")
	public Result getTreePage(PageModel pm, TVTrainCommentsQueryCriteria tVTrainCommentsQueryCriteria) {
		QueryWrapper wrapper = QueryWrapperUtil.getWrapper(pm, tVTrainCommentsQueryCriteria);
		return Result.buildOkData(service.findPage(pm, wrapper));
	}

	/**
	 * POST / : Save a tVTrainCommentsDto.
	 *
	 * @param tVTrainCommentsDto the HTTP tVTrainComments
	 */
//	@PreAuthorize("@pms.hasPermission('exam_tVTrainComments_edit')")
	@ApiOperation(value = "实验评论编辑")
	@PostMapping
	public Result save(@Valid @RequestBody TVTrainCommentsDto tVTrainCommentsDto) {
		log.debug("REST request to save TVTrainCommentsDto : {}", tVTrainCommentsDto);
		service.saveOrUpdate(tVTrainCommentsDto);
		return Result.buildOk("保存实验评论成功");

	}

	/**
	 * DELETE //:ids : delete the "ids" TVTrainComments.
	 *
	 * @param ids the id of the tVTrainComments to delete
	 * @return the Result with status 200 (OK)
	 */
	@PreAuthorize("@pms.hasPermission('exam_tVTrainComments_del')")
	@ApiOperation(value = "实验评论删除")
	@DeleteMapping
	public Result delete(@RequestBody Set<String> ids) {
		log.debug("REST request to delete TVTrainComments: {}", ids);
		service.removeByIds(ids);
		return Result.buildOk("删除实验评论成功");
	}
}
